package com.itheima.movement.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil;
import com.itheima.common.ThreadLocalUtil;
import com.itheima.entity.pojo.MovementCommentLike;
import com.itheima.entity.vo.MovementCommentLikeVo;
import com.itheima.movement.mapper.MovementCommentLikeMapper;
import com.itheima.movement.service.MovementCommentLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author :wujunjie
 * createTime :2022-12-23 14:33
 * description :
 */
@Service
public class MovementCommentLikeServiceImpl implements MovementCommentLikeService {
    @Autowired
    private MovementCommentLikeMapper movementCommentLikeMapper;

    @Override
    public Boolean insertLike(String movementCommentId) {
        MovementCommentLike movementCommentLikeInDB=movementCommentLikeMapper.selectBymovementCommentIdAndUserId(movementCommentId,ThreadLocalUtil.getId());
        MovementCommentLike movementCommentLike = new MovementCommentLike();
        movementCommentLike.setMovementCommentId(movementCommentId);
        movementCommentLike.setId(IdUtil.getSnowflakeNextIdStr());
        movementCommentLike.setCreateTime(LocalDateTime.now());
        movementCommentLike.setUserId(ThreadLocalUtil.getId());

        return movementCommentLikeMapper.insertLike(movementCommentLike);
    }

    @Override
    public Boolean deleteLike(String id) {
        return movementCommentLikeMapper.deleteLike(id);
    }

    @Override
    public List<MovementCommentLikeVo> seleteByMovementCommentIds(List<String> movementCommentIds) {
        List<MovementCommentLike> movementCommentLikes= movementCommentLikeMapper.selectByMovementCommentIds(movementCommentIds);
        return BeanUtil.copyToList(movementCommentLikes, MovementCommentLikeVo.class);
    }
}
